import 'package:star_author/widgets/no_data_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../config/base_configuration.dart';
import '../../config/ui_constant.dart';
import '../../utils/common_util/toast/custom_toast.dart';
import '../../utils/http/http_util.dart';
import '../../widgets/base_widget/app_bar/custom_app_bar_simple.dart';
import '../../widgets/button_widget.dart';
import '../../widgets/cover_widget.dart';

class MuteListPage extends StatefulWidget {
  const MuteListPage({Key? key}) : super(key: key);

  @override
  State<MuteListPage> createState() => _MuteListPageState();
}

class _MuteListPageState extends State<MuteListPage> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getList();
  }

  getList() async {
    ///api/v1/studios/{id}/banned_user_list
    await HttpUtil.commonRequest(Get.context!,
            "/api/v1/studios/${StreamConf.liveId}/banned_user_list",
            isErrorToast: false, isCatchErrorLogin: false, isLoading: false)
        .then((value) {
      setState(() {
        list = value.data['data'] ?? [];
      });
    });
  }

  List list = [];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppBarSimple("禁言名单"),
      backgroundColor: Colors.white,
      body: Container(
        color: Colors.white,
        child: list.length == 0
            ? Container(
                child: NoDataView(
                  height: Get.height,
                ),
              )
            : ListView.builder(
                itemBuilder: (context, index) {
                  return Container(
                      height: 78.w,
                      padding: EdgeInsets.only(left: 12.w, right: 12.w),
                      decoration: BoxDecoration(
                          border: Border(
                              bottom: BorderSide(
                        color: Color(0xFFEEEEEE),
                        width: 1,
                      ))),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Row(
                            children: [
                              buildCircleCover(
                                  size: 40, cover: list[index]['avatar'] ?? ""),
                              SizedBox(
                                width: 9.w,
                              ),
                              Container(
                                child: Column(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceAround,
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Text(
                                      "${list[index]['nickname'] ?? ""}",
                                      style: TextStyle(
                                        fontSize: 14.sp,
                                        color: UIConstant.color33,
                                      ),
                                    ),
                                    Text(
                                      "到${list[index]['time'] ?? ""}自动解禁",
                                      style: TextStyle(
                                        fontSize: 12.sp,
                                        color: UIConstant.color99,
                                      ),
                                    ),
                                  ],
                                ),
                                height: 40.w,
                              )
                            ],
                          ),
                          ButtonWidget(
                            child: Text(
                              "解禁",
                              style: TextStyle(
                                  fontSize: 14.sp, color: UIConstant.color33),
                            ),
                            type: ButtonType.bdGray,
                            width: 68,
                            height: 28,
                            onPressed: () {
                              uBand(index, list[index]['id']);
                            },
                          ),
                        ],
                      ));
                },
                itemCount: list.length,
              ),
      ),
    );
  }

  uBand(index, id) {
    HttpUtil.commonRequest(
        Get.context!, "/api/v1/studios/${StreamConf.liveId}/unban_user",
        method: HttpUtil.MethodPost, data: {"user_id": id}).then((value) {
      if (value.statusCode == 200) {
        getList();
        CustomToast.show("取消禁言成功");
      }
    });
  }
}
